package addon.w3.w3x;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;

public abstract class W3XCom {
	LEDataInputStream lein;
	
	public W3XCom() {
	}
	
	public W3XCom(byte data[]) {
		this.lein = new LEDataInputStream(new ByteArrayInputStream(data));
	}
	
	public W3XCom(LEDataInputStream lein) {
		this.lein = lein;
	}
	
	public void decode() throws W3XException, IOException {
		_decode();
	}
	
	public abstract void _decode() throws W3XException, IOException;
	
	public void debug(String s) {
		StringBuffer sb = new StringBuffer();
		sb.append("-------------------- DEBUG : "+this.getClass().getName());
		sb.append("\n");
		sb.append(s);
		sb.append("\n-------------------- DEBUG : "+this.getClass().getName());
		System.out.println(sb);
	}
	
	public void debug(int length) throws IOException {
		byte temp[] = new byte[length];
		lein.read(temp);
		lein.unread(temp);
		StringBuffer sb = new StringBuffer();
		sb.append("\n HEX : "+lein.toHex(temp, 0, temp.length) );
		sb.append("\n STR : "+new String(temp));
		debug( sb.toString() );
	}
	
	public Object get(String id) {
		return null;
	}
}
